import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-05-11
 * Time: 19:02
 */
public class MyStack {
    int[] elem;
    int usedSize;
    public MyStack(){
        this.elem=new int[5];
        this.usedSize=0;
    }
    private boolean isFull(){
        return usedSize==elem.length;
    }
    public void push(int data){
        if(isFull()){
            this.elem= Arrays.copyOf(this.elem,2*this.elem.length);
        }
        elem[usedSize++]=data;
    }
    public boolean empty(){
        return usedSize==0;
    }
    public int pop(){
        if(empty()){
            throw new RuntimeException("栈为空");
        }
        int tmp=elem[usedSize-1];
        usedSize--;
        return tmp;
    }
    public int size(){
        return usedSize;
    }
    public int peek(){
        return elem[usedSize-1];
    }
}
